// 登录注册表单验证模块

//导入验证模块
const joi = require('joi')

const username = joi.string().min(1).max(10).required()
const password = joi.string().pattern(/^[\S]{6,12}$/).required()

const phone = joi.string().pattern(/^1[3-9]\d{9}$/).required()
const email = joi.string().email().required()
const avatar = joi.string().required()



//定义验证和登录注册规则对象
exports.reg_login_schema = {
    body:{
        username,
        password
    }
}

exports.update_userinfo_schema = {
    body:{
        phone:phone,
        email:email,
        avatar:avatar
    }
}

exports.update_password_schema = {
    body:{
        oldPwd:password,
        newPwd:joi.not(joi.ref('oldPwd')).concat(password)//不能和原密码保持一致
    }
}